#
# @lc app=leetcode.cn id=977 lang=python3
#
# [977] 有序数组的平方
#

# @lc code=start
class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        result = [float('inf') ] * len(nums)
        left = 0
        right = len(nums) - 1 
        result_index = len(nums) - 1
        while left <= right:
            if nums[left] ** 2  >  nums[right] ** 2 :
                result[result_index] = nums[left] ** 2
                left += 1
            else:
                result[result_index] = nums[right] ** 2
                right -= 1
            result_index -= 1
        return result

# @lc code=end

